<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;
//电影表控制器
class Movie extends Controller
{

    public function movieshow()
    {
    //  return 'aaaaa';
        $list = Db::table('movie')->order('id','desc')->select();

        return  view('index/movie',[
            'title' => '电影表',
            'list' => $list,
        ]);
    }

    //电影删除
    public function delete($id)
    {
        $result = Db::table('movie')->delete($id);

        if ($result > 0 ) {
            $info['status'] = true;
            $info['id'] = $id;
            $info['info'] = 'ID为: ' . $id . ' 的用户已删除';
        } else {
            $info['status'] = false;
            $info['id'] = $id;
            $info['info'] = 'ID为: ' . $id . ' 的用户删除失败,请重试!';
        }

        return json($info);
    }

    //----------------------------start---------------------------------------
    //电影添加
    public function create(){
        return view('index/moviecreate',[
            'title' => '电影添加页',
        ]);
    }

    public function save(Request $request){
        // var_dump($request);
        $p = Request::instance()->post();
//        dump($p);
        //处理数据
        $data = [
            'moviename' => $p['moviename'],
            'movietype' => $p['movietype'],
            'playingtype' => $p['playingtype'],
            'duration' =>  $p['duration'],
            'rating' => $p['rating'],
            'playingtime' =>  $p['playingtime'],
            'description' => $p['description']
        ];
//                dump($data);


        $result = Db::name('movie')->data($data)->insert();
//        dump($result);

        if($result > 0) {
            return $this->success('添加成功',url('admin/movie/movieshow'));
        } else {
            return $this->error('添加失败(ノ°ο°)ノ高能预警');

        }
    }
    //---------------------------end-------------------------------------


}



















